library(tidyverse)
library(glue)
library(purrr)
require("tm")
require("tm.plugin.mail")
list.files(path)
path = '~/Ex-Felon Audit/02_Data/Emails/Sent/'
list.files(path)
path = '~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/02_Data/Emails/Sent/'
list.files(path)
list.files(path)[grepl('mbox',list.files(path))]
list.files(path)[grepl('mbox',list.files(path))]
list.files(path)[!grepl('mbox',list.files(path))]
lab = str_replace(f,'\\.mbox','')
f=list.files(path)[grepl('mbox',list.files(path))][1]
f
str_replace(f,'\\.mbox','')
list.files(path)[!grepl('mbox',list.files(path))]
lab%in% list.files(path)[!grepl('mbox',list.files(path))]
lab%in% list.files(path)[!grepl('mbox',list.files(path))]
lab
lab = str_replace(f,'\\.mbox','')
!lab%in% list.files(path)[!grepl('mbox',list.files(path))]
lab%in% list.files(path)[!grepl('mbox',list.files(path))]
f=list.files(path)[grepl('mbox',list.files(path))][2]
f
!lab%in% list.files(path)[!grepl('mbox',list.files(path))]
lab = str_replace(f,'\\.mbox','')
!lab%in% list.files(path)[!grepl('mbox',list.files(path))]
convert_mbox_eml(glue('{path}{f}'), glue('{path}{lab}'))
require(tm)
require(tm.plugin.mail)
convert_mbox_eml(glue('{path}{f}'), glue('{path}{lab}'))
source("~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/01_Code/administer_experiment/check-sent.R", echo=TRUE)
rm(list=ls())
gc()
# Check if any school emails not sent
library(tidyverse)
library(glue)
library(purrr)
require(tm)
require(tm.plugin.mail)
path = '~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/02_Data/Emails/Sent/'
for(f in list.files(path)[grepl('mbox',list.files(path))]){
lab = str_replace(f,'\\.mbox','')
if(!lab%in% list.files(path)[!grepl('mbox',list.files(path))]){
convert_mbox_eml(glue('{path}{f}'), glue('{path}{lab}'))
}
}
read_file(glue('path/andy-wang7016/001'))
read_file(glue('{path}/andy-wang7016/001'))
newsgroup <- system.file("glue('{path}/andy-wang7016')", package = "tm.plugin.mail")
newsgroup
newsgroup <- system.file("glue('{path}/andy-wang7016/001')", package = "tm.plugin.mail")
debugSource("~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/01_Code/administer_experiment/check-sent.R", echo=TRUE)
newsgroup
newsgroup <- system.file(glue('{path}/andy-wang7016/001'), package = "tm.plugin.mail")
rm(list=ls())
gc()
# Check if any school emails not sent
library(tidyverse)
library(glue)
library(purrr)
require(tm)
require(tm.plugin.mail)
path = '~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/02_Data/Emails/Sent/'
newsgroup <- system.file(glue('{path}/andy-wang7016/001'), package = "tm.plugin.mail")
newsgroup
readMail(glue('{path}/andy-wang7016/001'))
?readMail
check = readMail()
check
check(glue('{path}/andy-wang7016/001'))
readMail(glue('{path}/andy-wang7016/001'))
read_file(glue('{path}/andy-wang7016/001'))
read_delim(glue('{path}/andy-wang7016/001'), sep = '\n')
read_delim(glue('{path}/andy-wang7016/001'), delim = '\n')
mails <- VCorpus(DirSource(glue('{path}/andy-wang7016/')), readerControl = list(reader =
readMail))
mails
inspect(mails)
mails[[1]]
mails[[1]]|>as.character()
mails[[1]]|>as.data.frame()
inspect(mails)
mails[[1]]|>print()
data(mails)
cast(mails)
tidy(mails)
library(tidyverse)
tidy(mails)
library(tidytext)
tidy(mails)
install.packages()
install.packages('tidytext')
library(tidytext)
tidy(mails)
library(lubridate)
tidy(mails) |>
filter(ymd(datetimestamp)>ymd('09-23-2024'))
tidy(mails) |>
filter(datetimestamp>ymd('09-23-2024'))
dat = tidy(mails)
dat
dat$datetimestamp[1]
ymd("2024-10-02 15:31:21 GMT")
ymd_hms("2024-10-02 15:31:21 GMT")
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=ymd('09-23-2024'))
ymd('09-23-2024')
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))
tidy(mails)
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))
tidy(mails) |>
filter(ymd_hms(datetimestamp)<mdy('09-23-2024'))
dat = tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))
dat$header
dat$header[[1]]
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))|>
unnest()
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))|>
unnest(cols = header)
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))|>
unnest(cols = 'header')
unnest
?unnest
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))|>
unnest(cols = header)
dat = tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))|>
unnest(cols = header)
dat$header$`Delivered-To`
dat = tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))
dat$header$`Delivered-To`
dat$header$
dat
dat
dat$header$204
dat$header
dat$header[1]
dat$header[1][[1]]
tidy(mails) |>
filter(ymd_hms(datetimestamp)>=mdy('09-23-2024'))|>
unnest(cols = `Delivered-To`)
i=1
holder = dat$header[i]
holder
holder = dat$header[i][[1]]
holder
holder$`Content-Type`
holder$Subject
holder$Subject
holder$Received
holder$Date
holder$`Delivered-To`
holder$To
holder$From
holder$`X-Received`
holder$`DKIM-Signature`
holder$`X-Gmail-Labels`
out = 1:nrow(dat) |>
list()|>
pmap(
.f = function(i){
holder = dat$header[i][[1]]
tibble(from_email = holder$From,
to_email = holder$to,
date = holder$Date
)|>
return()
}
)
out = 1:nrow(dat) |>
list()|>
pmap(
.f = function(i){
holder = dat$header[i][[1]]
tibble(from_email = holder$From,
to_email = holder$to,
date = holder$Date
)
}
) |>
do.call(what='bind_rows')
out
out = 1:nrow(dat) |>
list()|>
pmap(
.f = function(i){
holder = dat$header[i][[1]]
tibble(from_email = holder$From,
to_email = holder$To,
date = holder$Date
)
}
) |>
do.call(what='bind_rows')
out
out = 1:nrow(dat) |>
list()|>
pmap(
.f = function(i){
holder = dat$header[i][[1]]
tibble(from_email = holder$From,
to_email = holder$To,
date = holder$Date
)
}
) |>
do.call(what='bind_rows') |>
filter(!grepl(from_email,to_email))
out
out = 1:nrow(dat) |>
list()|>
pmap(
.f = function(i){
holder = dat$header[i][[1]]
tibble(from_email = holder$From,
to_email = holder$To,
date = holder$Date
)
}
) |>
do.call(what='bind_rows')
out |> filter('andy.wang7016',to_email)
out |> filter(!grepl('andy.wang7016',to_email))
1:nrow(dat) |>
list()|>
pmap(
.f = function(i){
holder = dat$header[i][[1]]
tibble(from_email = holder$From,
to_email = holder$To,
date = holder$Date
)
}
) |>
do.call(what='bind_rows') |>
filter(!grepl(from_email,to_email))
out = 1:nrow(dat) |>
list()|>
pmap(
.f = function(i){
holder = dat$header[i][[1]]
tibble(from_email = holder$From,
to_email = holder$To,
date = holder$Date
)
}
) |>
do.call(what='bind_rows') |>
filter(!grepl(from_email,to_email))
out
list.files(path)[!grepl('mbox',list.files(path))]
source("~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/01_Code/administer_experiment/check-sent.R", echo=TRUE)
dat
nrow(dat)-3015
dat |> group_by(to_email)|>summarise(n=n())|>n_distinct(n)
dat |> group_by(to_email)|>summarise(n=n())|>group_by(n())|>summarise()
dat |> group_by(to_email)|>summarise(n=n())|>group_by(n|>summarise()
)
dat |> group_by(to_email)|>summarise(n=n())
check=dat |> group_by(to_email)|>summarise(n=n())
table(check$n)
check |> filter(n==4)
dat |> filter(to_email=='admission@sunyacc.edu ')
dat |> filter(to_email=='admission@sunyacc.edu')
dat |> filter(to_email=='admissions@eastcentral.edu')
dat = dat |>
group_by(to_email)|>
mutate(n=n())|>
ungroup()
###
check = read_csv('~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/02_Data/schools-treatment-assigned.csv')
emails1 = c('tyrone.booker143@gmail.com',
'tyrone.booker134@gmail.com',
'kevin.schmidt143@gmail.com',
'kevin.schmidt134@gmail.com',
'bob.krueger143@gmail.com',
'bob.krueger134@gmail.com',
'darnell.banks143@gmail.com',
'darnell.banks134@gmail.com')
emails2 =  c(
'peter.li7106@gmail.com',
'peter.li7016@gmail.com',
'andy.wang7106@gmail.com',
'andy.wang7016@gmail.com',
'william.snyder7016@gmail.com',
'william.snyder7106@gmail.com',
'david.hoffman7016@gmail.com',
'david.hoffman7106@gmail.com',
'jermaine.wood7016@gmail.com',
'jermaine.wood7106@gmail.com',
'jermaine.williams7016@gmail.com',
'jermaine.williams7106@gmail.com')
dat = dat |>
mutate(experiment = case_when(
from_email %in% emails1 ~ 1,
from_email %in% emails2 ~ 2
))
table(dat$experiment)
###
check = read_csv('~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/02_Data/schools-treatment-assigned.csv')
check$email
names(check)
check$study_1
unsent1 = check |>
filter(study_1==T & !email %in% dat$to_email[dat$experiment==1])|>
select(bhr_id,institution,email)
unsent1
unsent2 = check |>
filter(study_2==T & !email %in% dat$to_email[dat$experiment==2])|>
select(bhr_id,institution,email)
unsent2
dat |>
filter(experiment==1 & !to_email %in% check$email[check$study_1==T])|>
select(bhr_id,institution,email)
dat |>
filter(experiment==1 & !to_email %in% check$email[check$study_1==T])
not_listed2 = dat |>
filter(experiment==2 & !to_email %in% check$email[check$study_2==T])
source("~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/01_Code/administer_experiment/check-sent.R", echo=TRUE)
unsent1 |>
mutate(recode_email = str_replace(email,'\\.',''))|>
filter(!recode_email %in% dat$to_email[dat$experiment==1])
path
source("~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/01_Code/administer_experiment/check-sent.R", echo=TRUE)
unsent1|>
mutate(recode_email = str_sub(email,1,nchar(email)-1))|>
filter(!recode_email %in% dat$to_email[dat$experiment==1])
source("~/Research_Group Dropbox/Jacob Brown/Ex-Felon Audit/01_Code/administer_experiment/check-sent.R", echo=TRUE)
setwd("~/Documents/GitHub/prepost_paper/paper-replication")
## Packages ----
library(prepost)
library(gtools)
library(tidyverse)
library(forcats)
library(broom)
library(lmtest)
library(sandwich)
library(readstata13)
library(BayesLogit)
theme_set(theme_bw())
## Load source code ----
set.seed(13)
## Load and clean data ----
hk <-
read.dta13("data/Horowitz-Klaus-data.dta")
dat
hk
names(hk)
## Packages ----
library(prepost)
library(gtools)
library(tidyverse)
library(forcats)
library(broom)
library(lmtest)
library(sandwich)
library(readstata13)
library(BayesLogit)
theme_set(theme_bw())
## Load source code ----
set.seed(13)
## Load and clean data ----
hk <-
read.dta13("data/Horowitz-Klaus-data.dta")
## Packages ----
library(prepost)
library(gtools)
library(tidyverse)
library(forcats)
library(broom)
library(lmtest)
library(sandwich)
library(readstata13)
library(BayesLogit)
theme_set(theme_bw())
## Load source code ----
set.seed(13)
## Load and clean data ----
hk <-
read.dta13("data/Horowitz-Klaus-data.dta",nonint.factors = T)
dat
hk
as_tibble(hk)
## Packages ----
library(prepost)
library(gtools)
library(tidyverse)
library(forcats)
library(broom)
library(lmtest)
library(sandwich)
library(readstata13)
library(BayesLogit)
theme_set(theme_bw())
## Load source code ----
set.seed(13)
## Load and clean data ----
hk <-
read_dta("data/Horowitz-Klaus-data.dta",nonint.factors = T)
library(haven)
## Packages ----
library(prepost)
library(gtools)
library(tidyverse)
library(forcats)
library(broom)
library(lmtest)
library(sandwich)
library(readstata13)
library(BayesLogit)
theme_set(theme_bw())
## Load source code ----
set.seed(13)
## Load and clean data ----
hk <-
read_dta("data/Horowitz-Klaus-data.dta",nonint.factors = T)
## Packages ----
library(prepost)
library(gtools)
library(tidyverse)
library(forcats)
library(broom)
library(lmtest)
library(sandwich)
library(readstata13)
library(BayesLogit)
theme_set(theme_bw())
## Load source code ----
set.seed(13)
## Load and clean data ----
hk <-
read_dta("data/Horowitz-Klaus-data.dta")
hk
library(codebookr)
install.packages('codebookr')
library(codebookr)
codebook(hk)
str(hk)
tibble(vars = names(hk), sapply(hk,class))
t=tibble(vars = names(hk), sapply(hk,class))
t[,2]
t[1,2]
t[1,2]|>unlist()
tibble(vars = names(hk), sapply(hk,class)[[1]])
tibble(vars = names(hk), type = sapply(hk,class))
hk <-
read_dta("data/Horowitz-Klaus-data.dta")|>as.data.frame()
tibble(vars = names(hk), type = sapply(hk,class))
hk <-
read_dta("data/Horowitz-Klaus-data.dta")|>as.data.frame()
tibble(vars = names(hk), type = sapply(hk,class)|>unlist())
library(tidyverse)
library(haven)
library(codebookr)
hk <-
read_dta("data/Horowitz-Klaus-data.dta")
hk
hk <-
readdta13("data/Horowitz-Klaus-data.dta")
library(tidyverse)
library(haven)
library(codebookr)
hk <-
read.dta13("data/Horowitz-Klaus-data.dta")
hk
tibble(vars = names(hk), type = sapply(hk,class))
library(tidyverse)
library(haven)
library(codebookr)
hk <-
read.dta13("data/Horowitz-Klaus-data.dta")
tibble(vars = names(hk), type = sapply(hk,class))|>
write_csv(glue('codebooks/codebook-Horowitz-Klaus-data.csv'))
library(tidyverse)
library(haven)
library(codebookr)
hk <-
read.dta13("data/Horowitz-Klaus-data.dta")
tibble(vars = names(hk), type = sapply(hk,class))|>
write_csv(glue('codebooks/codebook-Horowitz-Klaus-data.csv'))
library(tidyverse)
library(haven)
library(codebookr)
hk <-
read.dta13("data/Horowitz-Klaus-data.dta")
tibble(vars = names(hk), type = sapply(hk,class))|>
write_csv(glue('codebooks/codebook-Horowitz-Klaus-data.csv'))
library(tidyverse)
library(haven)
library(codebookr)
hk <-
read_dta13("data/Horowitz-Klaus-data.dta")
hk <-
read_dta("data/Horowitz-Klaus-data.dta")
hk
hk |>select(eg)
hk |>select(female)
hk |>select(support_candidate)
hk |>select(violence_ever)
